package sanrenxing.dayEnd.backRepertoryTotal.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import sanrenxing.dayEnd.backRepertoryTotal.dao.StatisicalDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Statisical;
import sanrenxing.dayEnd.backRepertoryTotal.service.StatisicalBiz;

import java.util.List;

/**
 * 功能:
 * 编写者：
 * 日期：2021
 * 版本：1.0
 */
@Service("StatisicalBiz")
@Transactional(propagation = Propagation.REQUIRED)
public class StaticalBizImpl implements StatisicalBiz {
    @Autowired
    private StatisicalDao statisicalDao;


    /**
     * 分页查询条件
     *
     * @param rows
     * @param pages
     * @param condition
     * @return
     */
    @Override
    public List<Statisical> findByPages(int rows, int pages, String condition) {
        int start = (pages - 1) * rows;
        int row = (pages * rows) + 1;
        return statisicalDao.findByPage(start, row, condition);
    }

    /**
     * 按条件统计记录数
     *
     * @param condition 统计条件
     * @return 条件
     */
    @Override
    public int count(String condition) {
        return statisicalDao.count(condition);
    }

    /**
     * 获取查询条件
     *
     * @param statisical
     * @return 条件字符串
     */
    @Override
    public String getCount(Statisical statisical) {
        //定义空字符串
        String condition = "";
        //如果对象为空，则
        if (statisical == null) {
            return condition;
        }
        //如果交易日期不为空
        if (statisical.getTranDate() != null) {
            condition += "and tranDate=" + statisical.getTranDate();
        }
        return condition;
    }
}
